home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
051-075
/
scopedisk57
/
expand
/
system.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-19
|
4KB
|
188 lines
/*
* S Y S T E M . C
*
* System dependent routines for EXPAND, a utility to decompress files;
* compatible with the public domain COMPRESS v4.0 utility by Spencer W.
* Thomas, et al.
*
*-----------------------------------------------------------------------
* Author: Lyle V. Rains
*-----------------------------------------------------------------------
* Revision History:
*/
#define SYSTEM
#include <stdio.h>
#include "system.h"
#if DEBUGOUT
int debug = 0;
#endif
static int z_cmp();
/* The following two routines are system specific and will
* need to be modified for other systems.
*/
int to_xname(inname)
char * inname;
/* If inname ends with ZSUFFIX, then ZSUFFIX will be removed from inname
* and return (YES) otherwise don't modify inname and return (NO)
*/
{
char *c;
# ifdef MSDOS_FNAMES
int size;
/* If there is no file extension, or if it doesn't end in ZSUFFIX,
* forget it. The '.' in the file extension must occur within the
* last 4 characters, and there can be no path separator after it.
*/
c = inname + ((size = strlen(inname)) - 4 > 0 ? size - 4 : 0);
if ( (c = strrchr(c, '.')) == 0
|| strpbrk(c, "/\\")
|| z_cmp(c += strlen(c) - strlen(ZSUFFIX), ZSUFFIX)
)
{
return (NO);
}
else {
*c = '\0';
return (YES);
}
# else
/* Default: just check for ZSUFFIX at the end and get rid of it.
*/
if (z_cmp(c = inname + strlen(inname) - strlen(ZSUFFIX), ZSUFFIX)) {
return (NO);
}
else {
*c = '\0';
return (YES);
}
# endif
}
void to_zname(outname)
char * outname;
/* Add ZSUFFIX to end of outname. */
{
# ifdef MSDOS_FNAMES
char *c;
int size;
/* Find file extension (if any) and append ZSUFFIX to it,
* overwriting characters in the file extension as necessary.
*/
c = outname + ((size = strlen(outname)) - 4 > 0 ? size - 4 : 0);
if ( (c = strrchr(c, '.')) != 0 && strpbrk(c, "/\\") == 0) {
size = 3 - strlen(ZSUFFIX); /* Max # extension chars to keep */
while (*++c != '\0' && size--) /* empty loop */;
strcpy(c, ZSUFFIX);
}
else {
strcat(outname, "."ZSUFFIX);
}
return;
# else
char *c;
int maxzlen = MAXNAMELEN - strlen(ZSUFFIX);
char *filename();
/* Just concatenate ZSUFFIX onto size-adjusted outname */
c = filename(outname, PATHDELIM);
if (strlen(c) > maxzlen) {
c[maxzlen] = '\0';
}
strcat(outname, ZSUFFIX);
return;
# endif
}
#ifdef M_XENIX
# define EPRINTF
# include <varargs.h>
int eprintf(va_alist)
va_dcl
{
va_list args;
char *format;
va_start(args);
format = va_arg(args,char *);
return (vfprintf(stderr, format, args));
va_end(args);
}
#endif
#ifdef MWC
# define EPRINTF
int eprintf(format)
char *format;
{
return (fprintf(stderr, "%r", &format));
}
#endif
#ifdef MCH_AMIGA
# define EPRINTF
int eprintf(fmt, args)
char * fmt;
unsigned args;
{
extern int puterr();
return (format(puterr, fmt, &args));
}
#endif
#ifndef EPRINTF
# include <stdarg.h>
int eprintf(format)
char *format;
{
va_list args;
va_start(args, format);
return (vfprintf(stderr, format, args));
}
#endif
static int z_cmp(s1, s2)
register char *s1, *s2;
{
register int dif;
while ((dif = CASE(*s1) - CASE(*s2)) == 0 && *s1 != '\0') {
++s1;
++s2;
}
return (dif);
}
static char *filename(fullname, pathdelim)
char *fullname, *pathdelim;
/* Find the start of the filename after the path (if any) in fullname */
{
register char *nameptr, *delimptr;
for (nameptr = fullname + strlen(fullname); --nameptr != fullname; ) {
for (delimptr = pathdelim; *delimptr != '\0'; ++delimptr) {
if (*delimptr == *nameptr) return (nameptr + 1);
}
}
return (fullname);
}